<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.dic.service.UserService"%>
<jsp:directive.page import="com.dic.dao.*" />
<jsp:directive.page import="com.dic.dao.model.*" />
<jsp:directive.page import="com.dic.secure.*" />
<jsp:directive.page import="java.net.URLEncoder" />

<%
//System.out.println("aaa");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String action = request.getParameter("action");

//String ip = request.getRemoteAddr();
if("login".equals(action)) {
	String username = (String) request.getParameter("username");
	String password = (String) request.getParameter("password");
	String role = (String) request.getParameter("role");
	//int timeout = Integer.parseInt(request.getParameter("time"));
	
	if(role.equals("管理员")){
	    role="admin";
	}else if(role.equals("编撰者")){
	    role="worker";
	}
	//System.out.println(username+password+role);
	String res = "";
	User user1=new User(username,password,role);
	boolean Eflag = false;
	UserService ser = new UserService();
    User user = ser.checkExist(user1);
    //System.out.println("aa:"+user.getUsername());
	if(user!=null){
	   Eflag=true;
	}
	
	if(Eflag)  {
	    if(user.getRole().equals("admin")){
	      res = "admintrue";
	    }else if(user.getRole().equals("worker")){
	      res = "workertrue";
	    }
		
		session.setAttribute("username", username);
		session.setAttribute("password", password);
		session.setAttribute("role", role);
		
	} else if(!Eflag) {
		res = "false";
	}
	out.println("{'result' : '" + res + "', 'username' : '" + username + "', 'password' : '" + password + "'}");
} else if("logout".equals(action)) {

}
%>

